<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${package.Mapper}.${table.mapperName}">

    <#--VARCHAR BIGINT INTEGER TIMESTAMP DECIMAL-->

    <select id="get${entity}ById" resultType="${package.Entity}.${entity}">
        select
        <#list table.fields as field>
        <#if field_has_next>
            ${field.name},
        <#else>
            ${field.name}
        </#if>
        </#list>
        from ${table.name}
        where
        <#list table.fields as field>
        <#if field.keyFlag>
<#--            <if test="${field.propertyName} != null">-->
           ${field.name}=${r"#{"}${field.propertyName}}
<#--            </if>-->
        </#if>
        </#list>
    </select>

    <select id="list${entity}" resultType="${package.Entity}.${entity}" parameterType="${package.Entity}.${entity}">
        select
         <#list table.fields as field>
         <#if field_has_next>
             ${field.name},
         <#else>
             ${field.name}
         </#if>
         </#list>
        from ${table.name}
        <where>
            <#list table.fields as field>
            <#if field.columnType=='STRING'>
            <if test="${field.propertyName} != null and ${field.propertyName}!=''">
                and ${field.name}=${r"#{"}${field.propertyName}}
            </if>
            <#else>
            <if test="${field.propertyName} != null ">
                and ${field.name}=${r"#{"}${field.propertyName}}
            </if>
            </#if>
            </#list>
        </where>
    </select>

    <select id="pageList${entity}" resultType="${package.Entity}.${entity}" parameterType="${package.Entity}.${entity}">
        select
         <#list table.fields as field>
         <#if field_has_next>
             ${field.name},
         <#else>
             ${field.name}
         </#if>
         </#list>
        from ${table.name}
        <where>
            <#list table.fields as field>
            <#if field.columnType=='STRING'>
            <if test="${field.propertyName} != null and ${field.propertyName}!=''">
                and ${field.name}=${r"#{"}${field.propertyName}}
            </if>
            <#else>
            <if test="${field.propertyName} != null ">
                and ${field.name}=${r"#{"}${field.propertyName}}
            </if>
            </#if>
            </#list>
        </where>
    </select>

    <insert id="add${entity}" keyProperty="<#list table.fields as field><#if field.keyFlag>${field.propertyName}</#if></#list>" useGeneratedKeys="true">
        insert into ${table.name}(
        <#list table.fields as field>
        <#if field_has_next>
            ${field.name},
        <#else>
            ${field.name})
        </#if>
        </#list>
        values(
        <#list table.fields as field>
        <#if field_has_next>
            ${r"#{"}${field.propertyName}},
        <#else>
            ${r"#{"}${field.propertyName}})
        </#if>
        </#list>
    </insert>

    <update id="upd${entity}">
        update ${table.name}
        <trim prefix="set" suffixOverrides=",">
        <#list table.fields as field>
                <#--<#if field_has_next>-->
        <#if !field.keyFlag>
            <#if field.columnType=='STRING'>
            <if test="${field.propertyName} != null and ${field.propertyName}!=''">
                ${field.name}=${r"#{"}${field.propertyName}},
            </if>
            <#else>
            <if test="${field.propertyName} != null ">
                ${field.name}=${r"#{"}${field.propertyName}},
            </if>
            </#if>
        </#if>
                <#--<#else>-->
                    <#--<#if !field.keyFlag>-->
                        <#--<#if field.columnType=='STRING'>-->
                        <#--<if test="${field.propertyName} != null and ${field.propertyName}!=''">-->
                            <#--${field.name}=${r"#{"}${field.propertyName}}-->
                        <#--</if>-->
                        <#--<#else>-->
                        <#--<if test="${field.propertyName} != null ">-->
                            <#--${field.name}=${r"#{"}${field.propertyName}}-->
                        <#--</if>-->
                        <#--</#if>-->
                    <#--</#if>-->
                <#--</#if>-->
        </#list>
        </trim>
        where <#list table.fields as field><#if field.keyFlag>${field.name}=${r"#{"}${field.propertyName}}</#if></#list>
    </update>

    <update id="del${entity}">
        update ${table.name} set state = 0
        where
         <#list table.fields as field>
         <#if field.keyFlag>
           <#--<if test="${field.propertyName} != null">-->
               ${field.name}=${r"#{"}${field.propertyName}}

           <#--</if>-->
         </#if>
         </#list>
    </update>

    <#--<delete id="delete${entity}ById" >
        delete from ${table.name}
        <trim prefix="where" prefixOverrides="and | or">
             <#list table.fields as field>
                 <#if field.keyFlag>
                   <if test="${field.propertyName} != null">
                       and ${field.name}=${r"#{"}${field.propertyName}}
                   </if>
                 </#if>
             </#list>
        </trim>
    </delete>-->
</mapper>